package com.stockz.ui.swing.charting.widget;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.stockz.core.util.Global;
import com.stockz.ui.swing.charting.util.RepaintStockChartPanelUtil;
import com.stockz.ui.swing.charting.util.UIChartingConstant;
import com.stockz.ui.swing.charting.view.StockChartPanel;
import com.stockz.ui.swing.charting.view.StockChartPanelState;
import com.stockz.ui.swing.widget.JButton;

public class SemiLogButton extends JButton implements ActionListener {
	private static final long serialVersionUID = 3816910076124277741L;
	
	public SemiLogButton(){
		super("Semilog");
		addActionListener(this);
	}
	
	@Override
	public void actionPerformed(ActionEvent event) {
		StockChartPanel stockChartPanel = (StockChartPanel)Global.get(UIChartingConstant.SelectedStockChartPanel);
		if(stockChartPanel != null){
			StockChartPanelState state = stockChartPanel.getStockChartPanelState();
			if(state.isSemiLog()){
				state.setSemiLog(false);
				setText("Semilog");
			}else{
				state.setSemiLog(true);
				setText("Linier");
			}
			RepaintStockChartPanelUtil.repaintStockChartPanel(stockChartPanel);
		}
	}
}
